package com.example.brazil_project.util;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.widget.RemoteViews;

import com.example.brazil_project.Arrive_air_trsActivity;
import com.example.brazil_project.MsgActivity;
import com.example.brazil_project.R;

public class SendMsgUtil {
	/**
	 * 
	 * @param contxt上下文	
	 * @param title 标题
	 * @param msg	内容
	 * @param rang 声音
	 * @param ioc 	图标
	 * @param msgID msgID
	 */
	public static void sengNotification(Activity contxt,String title, String msg,String rang,String ioc ,int msgID){
		

		
		 NotificationManager manager = (NotificationManager) contxt.getSystemService(contxt.NOTIFICATION_SERVICE);  
		 
		 //跳转
		 PendingIntent pendingIntent = PendingIntent.getActivity(contxt, 0,  
                new Intent(contxt, MsgActivity.class), 0);  
		 
		 
        // 下面需兼容Android 2.x版本是的处理方式  
        // Notification notify1 = new Notification(R.drawable.message,  
        // "TickerText:" + "您有新短消息，请注意查收！", System.currentTimeMillis());  
        Notification notify1 = new Notification();  
        notify1.icon = R.drawable.ic_launcher;  
        notify1.tickerText = "TickerText:您有新短消息，请注意查收！";  
        notify1.when = System.currentTimeMillis();  
        notify1.setLatestEventInfo(contxt, "到空运信息",  //标题
                "新货到达", pendingIntent);  //内容
        notify1.number = 1; 
        
        
        RemoteViews contentView = new RemoteViews(contxt.getPackageName(), R.layout.custom_notification);
        //Bitmap  bitmap=BitmapUtil.zoomImage(BitmapUtil.getBitmapFromSD("/DCIM/Camera/IMG.jpg"), 100, 100);
        //默认图标
        Bitmap bitmap=BitmapUtil.drawableToBitmap(contxt.getResources().getDrawable(R.drawable.ic_launcher)); 
        //如果有传入图标
        if(ioc!=null&&!ioc.equals("")){
        	 bitmap=BitmapUtil.zoomImage(BitmapUtil.getBitmap(ioc), 144, 144);   
        }
       
        contentView.setImageViewBitmap(R.id.image, bitmap);
        contentView.setTextViewText(R.id.title,title );
        contentView.setTextViewText(R.id.text, msg);
        notify1.contentView = contentView;
       
        
       //notify1.flags |= Notification.FLAG_INSISTENT; // 一直进行，比如音乐一直播放，知道用户响
        
       
        
        notify1.defaults = Notification.DEFAULT_VIBRATE;// 设置默认震动  
        notify1.defaults = Notification.DEFAULT_ALL; // 设置铃声震动  
        
        
        notify1.flags |= Notification.FLAG_AUTO_CANCEL; // FLAG_AUTO_CANCEL表明当通知被用户点击时，通知将被清除。  
      //  notify1.flags = Notification.FLAG_ONGOING_EVENT; // 点击清除按钮不会清除消息通知,可以用来表示在正在运行  
        
        if(rang!=null&&!rang.equals("")){
        	notify1.sound = Uri.parse(rang); // 自定义声音  
        }else
        {
        	notify1.defaults = Notification.DEFAULT_SOUND; // 调用系统自带声音  
        }
        
        
        // 通过通知管理器来发起通知。如果id不同，则每click，在statu那里增加一个提示  
        manager.notify(msgID, notify1); 
	    
	}
	/**
	 * 
	 * @param contxt上下文	
	 * @param title 标题
	 * @param msg 内容
	 * @param msgID 提醒ID
	 */
	public static void sengNotification(Activity contxt,String title, String msg,int msgID){
		sengNotification( contxt, title,  msg, null, null , msgID);
	}
}
